package com.itheima.controller;


import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice  // 声明 rest风格的异常处理
public class ProjectExceptionAdvice {


    @ExceptionHandler(Exception.class)
    public Result doOtherException(Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
        String message = "请过段时间再来试一下~";
        if(e.getMessage().contains("Data too long for column")){
            message = "你输入的类型太长了";
        }
        return new Result(Code.SYSTEM_ERR, message, e);
    }


    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException e) {
        e.printStackTrace();
        System.out.println(e.getMessage());
        return new Result(e.getCode(), e.getMessage(), e);
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(SystemException e) {
        e.printStackTrace();
        return new Result(e.getCode(), e.getMessage(), e);
    }
}
